<blockquote class="layui-elem-quote">
  <div class="layui-inline">
    <i class="layui-icon layui-icon-list layui-head-icon"></i>
    <span class="layui-font-16 layui-font-green">优惠券管理</span>
  </div>
  <div class="layui-pull-right">
    <a class="layui-btn layui-btn-primary layui-border-green" href="{:url('/store/market/coupon/create')}">添加优惠券</a>
  </div>
</blockquote>
<div class="layui-card">
  <div class="layui-card-body">
    <fieldset class="layui-elem-field">
      <legend>条件搜索</legend>
      <div class="layui-field-box">
        <form class="layui-form layui-form-pane" action="{:url('/store/market/coupon')}" method="GET">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">优惠券类型</label>
                <div class="layui-input-inline">
                  <select name="coupon_type">
                    <option value="">请选择优惠券类型</option>
                    <option value="1">满减卷</option>
                    <option value="2">立减劵</option>
                    <option value="3">拼图卷</option>
                    <option value="4">转卖卷</option>
                  </select>
                </div>
            </div>
              
            <div class="layui-inline">
              <label class="layui-form-label">优惠券名称</label>
              <div class="layui-input-inline">
                <input type="text" name="keyword"  placeholder="请输入优惠名称" autocomplete="off" class="layui-input">
              </div> 
            </div>
            <div class="layui-inline">
              <div class="layui-input-inline">
                <button  class="layui-btn" lay-submit lay-filter="search">搜索</button>
              </div>
            </div>
          </div>
        </form>   
      </div>
    </fieldset>
    <form class="layui-form">
      <table class="layui-table">
        <thead>
          <tr>
            <th>ID</th>
            <th>优惠券图标</th>
            <th>优惠券类型</th>
            <th>优惠券名称</th>
            <th>有效时间</th>
            <th>优惠券配额</th>
            <th>领取数量</th>
            <th>状态</th>
            <th>创建时间</th>
            <th>更新时间</th>
            <th>操作</th>
          </tr> 
        </thead>
      <tbody>
      {foreach $list as $vo}
      <tr>
        <td>{$vo.id}</td>
        <td><img src="{$vo.icon}" class="layui-view-img"></td>
        <td>{$vo.coupon_type}</td>
        <td>{$vo.coupon_name}</td>
        <td>
          {switch $vo.expire_type}
            {case 1}领取后{$vo.expire_day}天有效{/case}
            {case 2}{$start_time|date='Y-m-d H:i:s'}~{$end_time|date='Y-m-d H:i:s'}{/case}
          {/switch}

        </td>
        <td>{if $vo.quota==0}不限制数量{else/}{$vo.quota}{/if}</td>
        <td>{$vo.grant_count}</td>
        <td>
          {switch $vo.status}
              {case 0} <span class="layui-font-red">禁用</span> {/case}
              {case 1} <span class="layui-font-green">启用</span> {/case}
              {case -1} <span class="layui-font-yellow">已失效</span> {/case}
          {/switch}
        </td>
        <td>{$vo.create_time}</td>
        <td>{$vo.update_time}</td>
        <td>
          <a class="layui-btn layui-btn-sm layui-btn-primary layui-border-green choose-user">发放优惠券</a>
          <a class="layui-btn layui-btn-sm" href="{:url('/store/market/coupon/edit',['id'=> $vo.id])}">编辑</a>
          <a class="layui-btn layui-btn-sm layui-btn-danger del" data-url="{:url('/store/market/coupon/delete',['id'=> $vo.id])}">删除</a>
        </td>
      </tr>
      {/foreach}
      </tbody>
      </table>
  </form>  
    {$list|raw}
  </div>
</div>
<script>
  $('.choose-user').click(function () {
    layer.open({
      title: ['选择会员'],
      type: 2,
      area: ['1000px', '800px'],
      offset: '30px',
      btn: ['确定', '取消'],
      maxmin: true,
      content: '/store/user/option',
      yes: function (index, layero) {
        let checkbox = $(layero).find('iframe').contents().find('.son:checked');
        if (checkbox.length < 1) {
          layer.msg('请选择商品!', {icon: 2});
          return false;
        }

        let goodsInfo = [];


        checkbox.each(function () {
          goodsInfo.push({
            goods_id: $(this).val(),
            goods_name: $(this).parents('tr').find('.goods-name').text(),
            main_image: $(this).parents('tr').find('.main-image').attr('src')
          });
        })
        let param = [];

        let paramEle = $('#param');
        param = paramEle.val() ? JSON.parse(paramEle.val()).concat(goodsInfo) : goodsInfo;

        getUseGoodsInfo(param);

        parent.layer.close(index);
      }
    });

  });
</script>